//创建小仓库
import { defineStore } from 'pinia'
import {
  getCategory1,
  getCategory2,
  getCategory3,
} from '@/api/product/attr/index'
import type { Category } from './types/type'
let useCategoryStore = defineStore('Category', {
  state: (): Category => {
    return {
      c1Arr: [],
      c1Id: '',
      c2Arr: [],
      c2Id: '',
      c3Arr: [],
      c3Id: '',
    }
  },
  actions: {
    async getC1() {
      const result = await getCategory1()
      if (result.code == 200) {
        this.c1Arr = result.data
      } else {
        return Promise.reject(new Error('失败'))
      }
    },
    async getC2(c1Id: any) {
      const result = await getCategory2(c1Id)
      if (result.code == 200) {
        this.c2Arr = result.data
      } else {
        return Promise.reject(new Error('失败'))
      }
    },
    async getC3(c2Id: any) {
      const result = await getCategory3(c2Id)
      if (result.code == 200) {
        this.c3Arr = result.data
      } else {
        return Promise.reject(new Error('失败'))
      }
    },
  },
  getters: {},
})
export default useCategoryStore
